package org.alis.smallcc.designpatterns.behavior.iterator;

/**
 * 数组迭代器
 * @param <T> 类型
 * @author luochuan
 */
public class AggregateIterator<T> implements Iterator<T>{

	private Aggregate<T> aggregate;
	
	private int cursor;
	
	public AggregateIterator(Aggregate<T> aggregate) {
		this.aggregate = aggregate;
		this.cursor = 0;
	}
	
	@Override
	public boolean hasNext() {
		return cursor < aggregate.size();
	}

	@Override
	public T next() {
		return aggregate.get(cursor++);
	}

	@Override
	public T remove() {
		return aggregate.remove(cursor);
	}

}
